<template>
  <div class="application">
    <crumbs :bread="bread">
      <template #content>
        <template v-for="(item, idx) in dictSource">
          <div v-if="dataByDict[item.dictValue] && dataByDict[item.dictValue].length" :key="idx">
            <div class="app-class">{{ item.dictLabel }}</div>
            <div class="content">
              <a class="item item-hover" href="javascript:;" v-for="(value, key) in dataByDict[item.dictValue]" :key="key" @click="goSso(value.id)">
                <div class="item-icon">
                  <img :src="value.images ? value.images : require('@/assets/images/bg-6.png')" alt="" />
                  <span class="undo-num" v-if="value.pendCount">{{ value.pendCount }}</span>
                </div>
                <div class="label">{{ value.systemNameCn }}</div>
              </a>

              <div class="item" v-for="value in carouselStep - (dataByDict[item.dictValue].length % carouselStep)" :key="'key' + value"></div>
            </div>
          </div>
        </template>
      </template>
    </crumbs>
  </div>
</template>

<script lang="ts">
import Base from "@/controllers/base.ts";
import { Component } from "vue-property-decorator";
import Crumbs from "@/components/Crumbs/index.vue";
import CContentTop from "@/components/CContentTop.vue";

@Component({
  name: "Application",
  components: {
    Crumbs,
    CContentTop
  }
})
export default class Application extends Base {
  private dataSource: any[] = [];
  private dictSource: any[] = [];
  private carouselStep = 8;

  private created() {
    this._created();
    this.getSystemDict();
    this.ssoConfigAllList();
  }

  private async goSso(id: string) {
    const res = await this.$api.GetSsoUrl(id);
    if (res && res.code === 200) {
      if (res.data.URL) {
        this._goto(res.data.URL, res.data.openWay);
        // if (res.data.openWay === "1") {
        //   this.$tools.cOpenIE(this, res.data.URL);
        // } else {
        //   this.$tools.cOpen(res.data.URL);
        // }
      } else {
        this.$message.error("跳转地址为空");
      }
    }
  }

  private async ssoConfigAllList() {
    const res = await this.$api.SsoConfigAllList();
    if (res && res.code === 200) {
      this.dataSource = res.rows;
    }
  }

  private async getSystemDict() {
    const res = await this.$api.SystemDict("outside_system_type");
    if (res && res.code === 200) {
      this.dictSource = res.data;
    }
  }

  private get dataByDict() {
    const _return: any = {};
    for (const item of this.dataSource) {
      if (!_return[item.systemType]) {
        _return[item.systemType] = [];
      }

      _return[item.systemType].push(item);
    }
    return _return;
  }
}
</script>

<style lang="less" scoped>
@import "~@/assets/style/mixin.less";
.application {
  /deep/.crumbs-content {
    // .scale(padding-left, 60px);
    // .scale(padding-right, 60px);
  }

  .content {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding-bottom: 30px;

    & > .item {
      .scale(padding, 10px);
      .scale(margin-top, 6px);
      .scale(margin-bottom, 6px);
      text-align: center;
      flex-shrink: 0;
      .scale(width, 155px);
    }
    & > .item-hover {
      &:hover {
        border-radius: 2px;
        box-shadow: 0px 0px 10px 0px rgba(83, 112, 239, 0.22);
      }
    }
    // img {
    //   .scale(width, 41px);
    //   .scale(height, 41px);
    // }
    .item-icon {
      .scale(width, 80px);
      .scale(height, 80px);
      .scale(border-radius, 80px);
      background: rgba(188, 202, 212, 0.1);
      margin: 0 auto;
      display: flex;
      align-items: center;
      justify-content: center;
      .scale(margin-bottom, 10px);
      position: relative;

      img {
        .scale(width, 49px);
      }
    }

    .undo-num {
      position: absolute;
      background: #dd1b29;
      border-radius: 12px;
      height: 20px;
      width: 30px;
      color: white;
      line-height: 20px;
      display: block;
      font-size: 12px;
      text-align: center;
      top: 8px;
      right: -15px;
    }
    .label {
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
    }
  }
  .app-class {
    font-size: 18px;
    font-weight: bold;
    color: #333333;
    padding-top: 16px;
    padding-bottom: 16px;
    text-shadow: 0px 0px 2px #cccccc;
  }
}
</style>
